import { Component, OnInit,ViewChild,Input } from '@angular/core';
import {Service} from '../../server/server';
import {HttpClient} from '@angular/common/http';
import { HintsService } from '../../public/serve/hints/hints.service';
import { InitService } from '../../public/serve/init/init.service';
import {CudTableService} from '../../public/serve/cud-table/cud-table.service';
declare var $:any;

@Component({
    selector: 'app-internal-indexed-modal-add-version',
    templateUrl: './internal-indexed-modal-add-version.component.html',
    styleUrls: ['./internal-indexed-modal-add-version.component.css']
})
export class InternalIndexedModalAddVersionComponent implements OnInit {
  @Input() internalParam : any;
  constructor(  private request: CudTableService,private hintsService: HintsService,private server: Service,private http: HttpClient,public initService:InitService) { }
  @ViewChild('addForm') formElement: HTMLFormElement;
  ngOnInit() {
  }

  private _initAdd(){
      this.initService._init();
      this.formElement.reset();
      $("#addVersion").modal("hide");
  }

  _onSubmitVersion(info:any){
      info.taskId = this.internalParam.taskId;
      info.productId = this.internalParam.productId;
      info.themeTableId = this.internalParam.themeTableId;
      // info.file_content = '';
      info.createBy = this.server.getuserName();
      let url = this.server.baseUrl + 'Service/IdxProduct/setProductIndexingVersion';
      this.request
          .postRequest(url,info)
          .then(res =>{
              if(res.result_code == "0000"){
                  this.hintsService.messages(res.message,res.result_code);
                  this._initAdd();
              }
              return;
          })
          .catch(err =>{
              this.hintsService.messages("error","error");
              this._initAdd();
              return;
          });
  }
}